Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add validation for starting price in pool init #664

Merged
merged 5 commits into from
Apr 16, 2024

Conversation

p6te
Copy link
Collaborator

@p6te p6te commented Apr 11, 2024

Add validation for starting price in pool init.

@@ -101,9 +101,30 @@ export const PoolInit: React.FC<IPoolInit> = ({
changeRangeHandler(leftRange, rightRange)
}, [midPrice])

const validateMidPriceInput = (midPriceInput: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks quite complex. Iry it more this way:

const validateMidPriceInput = (midPriceInput, tickSpacing, isXtoY, xDecimal, yDecimal) => {
  const minTick = getMinTick(tickSpacing);
  const maxTick = getMaxTick(tickSpacing);

  const minPrice = isXtoY 
    ? calcPrice(minTick, isXtoY, xDecimal, yDecimal)
    : calcPrice(maxTick, isXtoY, xDecimal, yDecimal);
  const maxPrice = isXtoY 
    ? calcPrice(maxTick, isXtoY, xDecimal, yDecimal)
    : calcPrice(minTick, isXtoY, xDecimal, yDecimal);

  const numericMidPriceInput = parseFloat(midPriceInput);
  const validatedMidPrice = Math.min(Math.max(numericMidPriceInput, minPrice), maxPrice);

  return toMaxNumericPlaces(validatedMidPrice, 5);
}

Copy link

This pull request has been deployed to Vercel.

Latest commit: 2ab037a
✅ Preview: https://webapp-9hl2n8xtk-invariantlabs.vercel.app
🔍 Inspect: https://vercel.com/invariantlabs/webapp/AZ4S11QPmBbhiidtNQY6kQGNJtg2

View Workflow Logs

@p6te p6te merged commit 8c7c86a into dev Apr 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants